package com.example.midprojcampusspringboot.controller;

import com.example.midprojcampusspringboot.common.ResultUtil;
import com.example.midprojcampusspringboot.domain.entity.TCourse;
import com.example.midprojcampusspringboot.domain.params.CourseAddParams;
import com.example.midprojcampusspringboot.service.CourseService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 课程管理
 *
 * @Author Fengwei
 * @Description
 * a)课程创建（必做）：
 * b)学习单元（教学进度）管理（选做）：
 * 学习单元创建
 * 学习单元查询
 *
 **/
@RestController
@RequestMapping("/course")
public class CourseController {

    @Autowired
    private CourseService courseService;

    /**
     * 1.课程创建
     *
     **/
    @PostMapping("/create")
    public ResultUtil createCourse(@RequestBody @Validated CourseAddParams courseAddParams) {
        TCourse tManagerCourse = new TCourse();
        BeanUtils.copyProperties(courseAddParams, tManagerCourse);
        return courseService.save(tManagerCourse) ? ResultUtil.success("创建课程成功") : ResultUtil.error("创建课程失败");
    }
}
